home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 2 of 3.iso / chapter4 / setwizbn.c < prev    next >
C/C++ Source or Header  |  1996-03-06  |  9KB  |  323 lines

  1.  
  2. #include <windows.h>  
  3. #include "setwizbn.h"  
  4. #include "commctrl.h"
  5.  
  6.  
  7. #if defined (WIN32)
  8.     #define IS_WIN32 TRUE
  9. #else
  10.     #define IS_WIN32 FALSE
  11. #endif
  12.  
  13. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  14. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  15. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  16.  
  17. HINSTANCE hInst;   // current instance
  18.  
  19. LPCTSTR lpszAppName = "MyApp";
  20. LPCTSTR lpszTitle   = "PropSheet_SetWizButtons"; 
  21.  
  22.  
  23. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  24.  
  25.  
  26. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  27.                       LPTSTR lpCmdLine, int nCmdShow)
  28. {
  29.    MSG      msg;
  30.    HWND     hWnd; 
  31.    WNDCLASS wc;
  32.  
  33.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  34.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  35.    wc.cbClsExtra    = 0;                      
  36.    wc.cbWndExtra    = 0;                      
  37.    wc.hInstance     = hInstance;              
  38.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  39.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  40.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  41.    wc.lpszMenuName  = lpszAppName;              
  42.    wc.lpszClassName = lpszAppName;              
  43.  
  44.    if ( IS_WIN95 )
  45.    {
  46.       if ( !RegisterWin95( &wc ) )
  47.          return( FALSE );
  48.    }
  49.    else if ( !RegisterClass( &wc ) )
  50.       return( FALSE );
  51.  
  52.    hInst = hInstance; 
  53.  
  54.    hWnd = CreateWindow( lpszAppName, 
  55.                         lpszTitle,    
  56.                         WS_OVERLAPPEDWINDOW, 
  57.                         CW_USEDEFAULT, 0, 
  58.                         CW_USEDEFAULT, 0,  
  59.                         NULL,              
  60.                         NULL,              
  61.                         hInstance,         
  62.                         NULL               
  63.                       );
  64.  
  65.    if ( !hWnd ) 
  66.       return( FALSE );
  67.  
  68.    ShowWindow( hWnd, nCmdShow ); 
  69.    UpdateWindow( hWnd );         
  70.  
  71.    while( GetMessage( &msg, NULL, 0, 0) )   
  72.    {
  73.       TranslateMessage( &msg ); 
  74.       DispatchMessage( &msg );  
  75.    }
  76.  
  77.    return( msg.wParam ); 
  78. }
  79.  
  80.  
  81. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  82. {
  83.    WNDCLASSEX wcex;
  84.  
  85.    wcex.style         = lpwc->style;
  86.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  87.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  88.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  89.    wcex.hInstance     = lpwc->hInstance;
  90.    wcex.hIcon         = lpwc->hIcon;
  91.    wcex.hCursor       = lpwc->hCursor;
  92.    wcex.hbrBackground = lpwc->hbrBackground;
  93.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  94.    wcex.lpszClassName = lpwc->lpszClassName;
  95.  
  96.    // Added elements for Windows 95.
  97.    //...............................
  98.    wcex.cbSize = sizeof(WNDCLASSEX);
  99.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  100.                             IMAGE_ICON, 16, 16,
  101.                             LR_DEFAULTCOLOR );
  102.             
  103.    return RegisterClassEx( &wcex );
  104. }
  105.  
  106. #define IDBACK    12323
  107. #define IDNEXT    12324
  108. #define IDFINISH  12325
  109.  
  110. LRESULT CALLBACK Page1Proc( HWND hDlg, UINT message,        
  111.                             WPARAM wParam, LPARAM lParam )
  112. {
  113.    switch (message) 
  114.    {
  115.        case WM_INITDIALOG: 
  116.                return (TRUE);
  117.  
  118.        case WM_NOTIFY :
  119.                switch( ((NMHDR*)lParam)->code )
  120.                {
  121.                   case PSN_HELP :
  122.                        WinHelp( hDlg, "SETWIZBN.HLP", HELP_CONTEXTPOPUP, 100 );
  123.                        break;
  124.  
  125.                   case PSN_KILLACTIVE :
  126.                        WinHelp( hDlg, "SETWIZBN.HLP", HELP_QUIT, 0 );
  127.                        break;
  128.  
  129.                   case PSN_SETACTIVE :
  130.                        PropSheet_SetTitle( GetParent( hDlg ), 0, "Enter Text" );
  131.                        PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_NEXT );
  132.                        ShowWindow( GetDlgItem( GetParent( hDlg ), IDBACK ), SW_SHOW );
  133.                        break;
  134.  
  135.                   case PSN_WIZNEXT :
  136.                        if ( SendDlgItemMessage( hDlg, IDC_EDIT1, 
  137.                                                 EM_LINELENGTH, 0, 0 ) > 0 )
  138.                        {
  139.                           PropSheet_SetCurSel( GetParent( hDlg ), 0, 2 );
  140.                        }
  141.                        break;
  142.                }
  143.    }
  144.  
  145.    return( FALSE );
  146. }
  147.  
  148.  
  149. LRESULT CALLBACK Page2Proc( HWND hDlg, UINT message,        
  150.                             WPARAM wParam, LPARAM lParam )
  151. {
  152.    switch (message) 
  153.    {
  154.        case WM_INITDIALOG: 
  155.                return (TRUE);
  156.  
  157.        case WM_NOTIFY :
  158.                switch( ((NMHDR*)lParam)->code )
  159.                {
  160.                   case PSN_HELP :
  161.                        WinHelp( hDlg, "SETWIZBN.HLP", HELP_CONTEXTPOPUP, 200 );
  162.                        break;
  163.  
  164.                   case PSN_KILLACTIVE :
  165.                        WinHelp( hDlg, "SETWIZBN.HLP", HELP_QUIT, 0 );
  166.                        break;
  167.  
  168.                   case PSN_SETACTIVE :
  169.                        PropSheet_SetTitle( GetParent( hDlg ), 0, "Check a Box" );
  170.                        PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_NEXT | PSWIZB_BACK );
  171.                        break;
  172.  
  173.                   case PSN_WIZBACK :
  174.                        if ( IsDlgButtonChecked( hDlg, IDC_CHECK1 ) ||
  175.                             IsDlgButtonChecked( hDlg, IDC_CHECK2 ) )
  176.                        {
  177.                           MessageBox( hDlg, "Cannot go back because a box is checked.",
  178.                                       lpszTitle, MB_OK | MB_ICONASTERISK );
  179.                           return( -1 );
  180.                        }
  181.                        break;
  182.                }
  183.    }
  184.  
  185.    return( FALSE );
  186. }
  187.  
  188.  
  189. LRESULT CALLBACK Page3Proc( HWND hDlg, UINT message,        
  190.                             WPARAM wParam, LPARAM lParam )
  191. {
  192.    switch (message) 
  193.    {
  194.        case WM_INITDIALOG: 
  195.                return (TRUE);
  196.  
  197.        case WM_COMMAND :
  198.                if ( LOWORD( wParam ) == IDC_GOBACK )
  199.                   PropSheet_SetCurSelByID( GetParent( hDlg ), 100 );
  200.                break;
  201.  
  202.        case WM_NOTIFY :
  203.                switch( ((NMHDR*)lParam)->code )
  204.                {
  205.                   case PSN_HELP :
  206.                        WinHelp( hDlg, "SETWIZBN.HLP", HELP_CONTEXTPOPUP, 300 );
  207.                        break;
  208.  
  209.                   case PSN_KILLACTIVE :
  210.                        WinHelp( hDlg, "SETWIZBN.HLP", HELP_QUIT, 0 );
  211.                        break;
  212.  
  213.                   case PSN_SETACTIVE :
  214.                        PropSheet_SetTitle( GetParent( hDlg ), 0, "Choose a Button and Finish" );
  215.                        PropSheet_SetFinishText( GetParent( hDlg ), "Finish Wizard" );
  216.                        break;
  217.  
  218.                   case PSN_WIZFINISH :
  219.                        MessageBox( hDlg, "The wizard is finished.", 
  220.                                    lpszTitle, MB_OK | MB_ICONINFORMATION );
  221.                        break;
  222.                }
  223.    }
  224.  
  225.    return( FALSE );
  226. }
  227.  
  228.  
  229. VOID DisplayWizard( HWND hWnd )
  230. {
  231.    PROPSHEETPAGE   psp;
  232.    PROPSHEETHEADER psh;
  233.    HPROPSHEETPAGE  hpsp[3];
  234.  
  235.    psp.dwSize    = sizeof( PROPSHEETPAGE );
  236.    psp.dwFlags   = PSP_DEFAULT | PSP_HASHELP;
  237.    psp.hInstance = hInst;
  238.  
  239.    psp.pszTemplate = (LPCTSTR)100;
  240.    psp.pfnDlgProc  = (DLGPROC)Page1Proc;
  241.    hpsp[0] = CreatePropertySheetPage( &psp );
  242.  
  243.    psp.pszTemplate = (LPCTSTR)200;
  244.    psp.pfnDlgProc  = (DLGPROC)Page2Proc;
  245.    hpsp[1] = CreatePropertySheetPage( &psp );
  246.  
  247.    psp.pszTemplate = (LPCTSTR)300;
  248.    psp.pfnDlgProc  = (DLGPROC)Page3Proc;
  249.    hpsp[2] = CreatePropertySheetPage( &psp );
  250.  
  251.    memset( &psh, 0, sizeof( PROPSHEETHEADER ) );
  252.    psh.dwSize     = sizeof( PROPSHEETHEADER );
  253.    psh.dwFlags    = PSH_WIZARD | PSH_HASHELP;
  254.    psh.hInstance  = hInst;
  255.    psh.hwndParent = hWnd;
  256.    psh.nPages     = 3;
  257.    psh.phpage     = hpsp;
  258.    psh.pszCaption = NULL;
  259.  
  260.    PropertySheet( &psh );
  261. }
  262.  
  263.  
  264. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  265. {
  266.    switch( uMsg )
  267.    {
  268.       case WM_CREATE :
  269.               InitCommonControls();
  270.               break;
  271.  
  272.       case WM_COMMAND :
  273.               switch( LOWORD( wParam ) )
  274.               {
  275.                  case IDM_TEST :
  276.                         DisplayWizard( hWnd );
  277.                         break;
  278.  
  279.                  case IDM_ABOUT :
  280.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  281.                         break;
  282.  
  283.                  case IDM_EXIT :
  284.                         DestroyWindow( hWnd );
  285.                         break;
  286.               }
  287.               break;
  288.       
  289.       case WM_DESTROY :
  290.               PostQuitMessage(0);
  291.               break;
  292.  
  293.       default :
  294.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  295.    }
  296.  
  297.    return( 0L );
  298. }
  299.  
  300.  
  301. LRESULT CALLBACK About( HWND hDlg,           
  302.                         UINT message,        
  303.                         WPARAM wParam,       
  304.                         LPARAM lParam)
  305. {
  306.    switch (message) 
  307.    {
  308.        case WM_INITDIALOG: 
  309.                return (TRUE);
  310.  
  311.        case WM_COMMAND:                              
  312.                if (   LOWORD(wParam) == IDOK         
  313.                    || LOWORD(wParam) == IDCANCEL)    
  314.                {
  315.                        EndDialog(hDlg, TRUE);        
  316.                        return (TRUE);
  317.                }
  318.                break;
  319.    }
  320.  
  321.    return (FALSE); 
  322. }
  323.